﻿@{
    ViewBag.Title = "userQuan";
    Layout = "~/Views/Shared/ShouYe.cshtml";
}

<link href="~/Content/css/bootstrap.min.css" rel="stylesheet" />
<script src="~/Scripts/js/jquery.min.js"></script>
<script src="~/Scripts/js/bootstrap.min.js"></script>
<script src="~/Scripts/jquery-1.8.2.min.js"></script>
<style>
    * {
        margin: 0;
        padding: 0;
    }

dl,dt,dd{display:block;margin:0;}
a{text-decoration:none;}

.leftsidebar{width:200px;height:auto ;overflow:visible !important;position:fixed;background-color:#36e325;}
.line{height:2px;width:100%;}
.leftsidebar dt{padding-left:20px;padding-right:10px;background-repeat:no-repeat;background-position:10px center;font-size:16px;position:relative;line-height:48px;cursor:pointer;}
.leftsidebar dd{padding-left:40px;text-align:left;background-color:#b2e97f}
.leftsidebar dd a{color:#f5f5f5;line-height:10px;}
.leftsidebar dl dd:last-child{padding-bottom:10px;}
</style>
<div class="col-lg-12">
    <div class="col-lg-4">
        <p style="float:left;margin-left:100px;font-size:16px;">
          <select id="select">
              @foreach (var item in ViewBag.rolelist)
              {
                  <option value="@item.RoleId">@item.RoleName</option>
              }
          </select>
        </p>
    
    </div>
    <div class="col-lg-12" id="jsdiv">
        <div class="col-lg-4 leftsidebar" style="float:left;margin-left:40px;">


            @{
                foreach (var item in Model)
                {

                    if (@item.qfid == 0)
                    {
                        <dl>
                            <dt>
                                <input id="Checkbox1" name="checkone" type="checkbox" value="@item.qxId" />  @item.qxName
                            </dt>
                                @foreach (var child in Model)
                                {
                                    if (@child.qfid == @item.qxId)
                                    {
                                        <dd><span><input id="Checkbox1" name="checkone" type="checkbox" value="@child.qxId" /> @child.qxName</span></dd>
                                    }
                                    else
                                    {
                                        continue;
                                    }
                                }
</dl>
                    }
                    else
                    {
                        continue;
                    }
                }
            }
            <input type="button" class="btn btn-default" onclick="quanxuan('@ViewBag.Roleid ') " style="float:left;margin-left:20px;" value="确定" />
            <input type="button" class="btn btn-warning" onclick="fanhui()" style="float:left;margin-left:10px;" value="返回" />
</div>
        <div class="col-lg-4">
         
        </div>
    </div>
</div>
<script>
    function fanhui()
    {
        location.href = "/Home/showUser";
    }
    function quanxuan() {
        var RoleId = $("#select").val();
        $.ajax({
            url: "/Home/delQuan",
            type: "post",
            data: { roleid: RoleId },
            success: function (obj) {
                if (obj >= 0) {
                    //定义空值，用来存放下标
                    var str = "";
                    //获取多选框
                    var checkall = $("[name='checkone']:checked");
                    //判断选中复选框的长度
                    if (checkall.length == 0) {
                        alert("请选中要赋予的选项");
                    }

                    else {
                        //for（）循环选中的复选框
                        for (i = 0; i < checkall.length ; i++) {
                            if (i > 0) {
                                //添加 逗号
                                str += ",";
                            }
                            //选取复选框后的第一列，通常为编号 ID
                            str += checkall.eq(i).val();
                        }
                        $.ajax({
                            url: "/Home/addQuan",
                            type: "post",
                            data: { roleid: RoleId, qxids: str },
                            success: function (obj) {
                                if (obj > 0) {
                                    location.href = "/Home/showUser";
                                }
                                else {
                                    alert("权限分配出现失误，请重新分配！");
                                    location.href = "/Home/showUser";
                                }
                            }
                        })
                    }
                }
                else {

                    alert("该员工暂无任何权限。")
                }
            }
        })
    }
</script>
<script>
    $(function () {
        $(".leftsidebar dd").hide();
        $(".leftsidebar_box dt").css({ "background-color": "#3992d0" });
        $(".leftsidebar dt").click(function () {
            $(this).parent().find('dd').removeClass("menu_chioce");
            $(".menu_chioce").slideUp();
            $(this).parent().find('dd').slideToggle();
            $(this).parent().find('dd').addClass("menu_chioce");
        });
    })
</script>

